#pragma once
#include <stdio.h>
#include <list>
#include <string>
#include "BaseType.h"
#include "Lock\Lock.h"
#include "Singleton\Singleton.h"

#define LOG_DEBUF( x, ... )	G_Log->WriteDebugLog( x, __VA_ARGS__ )
#define LOG_ERROR( x, ... )	G_Log->WriteErrorLog( x, __VA_ARGS__ )
#define LOG_INFO( x, ... )	G_Log->WriteInfoLog( x, __VA_ARGS__ )
#define LOG_WARN( x, ... )	G_Log->WriteWarningLog( x, __VA_ARGS__ )

const int LOG_MAXSIZE = 2048;
const int LOG_TIMESIZE = 24;

class Log
{
public:
	Log();
	~Log();

public:
	bool Init( char* strFileName );

	void StartLog();
	void StopLog();

	Log& WriteErrorLog( const char* sMsg, ... );

	Log& WriteInfoLog( const char* sMsg, ... );

	Log& WriteDebugLog( const char* sMsg, ... );

	Log& WriteWarningLog( const char* sMsg, ... );

	void WriteLogFile();

public:
	static DWORD WINAPI LogProc( LPVOID pParam );

	void LogFun();

private:
	void WriteTime( );

	bool IsEmpty();

private:
	FILE*							m_pFile;
	std::string						m_sFileName;

	std::string						m_strBuff;

	char							m_aLogBuff[ LOG_MAXSIZE ];
	char							m_aTimeBuff[ LOG_TIMESIZE ];

	std::list< std::string >		m_aLogList;
	CLock*							m_pLock;

	bool							m_bShutDown;
};

typedef Singleton< Log >			Log_T;
#define G_Log						Log_T::GetInstance()
